﻿using System;
using PowerGui.AddOn.Interfaces.Properties;

namespace PowerGui.AddOn
{
    public class PowerGuiInstallationException : Exception
    {
        public bool IsInstalled { get; set; }

        public Version InstalledVersion { get; set; }

        public Version ExceptedVersion { get; set; }

        private PowerGuiInstallationException(string message, Version installedVersion, Version exceptedVersion, bool isInstalled) : base(message)
        {
            InstalledVersion = installedVersion;
            ExceptedVersion = exceptedVersion;
            IsInstalled = isInstalled;
        }

        private PowerGuiInstallationException(bool isInstalled, string message) : base(message)
        {
            IsInstalled = isInstalled;
            ExceptedVersion = Version.Parse(Resources. SupportedVersion);
        }

        public static void ThrowOnNotInstalled()
        {
            throw new PowerGuiInstallationException(false, Resources.PowerGUINotInstalled);
        }

        public static void ThrowOnInvalidVersion(Version installedVersion)
        {
            if (installedVersion != Version.Parse(Resources.SupportedVersion))
            {
                throw new PowerGuiInstallationException(String.Format(Resources.VersionNotSupported, Resources.SupportedVersion, installedVersion), installedVersion, Version.Parse(Resources.SupportedVersion), true);
            }
        }

    }
}
